package basic.com.liz.bean.entity.system;

import java.io.Serializable;
import java.util.Date;
import java.util.List;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.persistence.Transient;

import lombok.Data;

import org.apache.commons.lang3.builder.ToStringBuilder;

import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonProperty;

/**
 * <系统菜单实体类>
 * 
 * @author 陆小凤
 * @version [1.0, 2015年7月17日]
 * @see [相关类/方法]
 * @since [播控管理系统]
 */
@Data
@Entity
@Table(name = "system_menu")
public class SysMenu implements Serializable
{
    private static final long serialVersionUID = 1L;
    
    @Id
    @Column(name = "MENU_ID")
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Long id;
    
    @Column(name = "MENU_NAME")
    private String name;
    
    @Column(name = "MENU_ALIAS")
    private String alias;
    
    @Column(name = "MENU_DESC")
    private String description;
    
    @Column(name = "MENU_LINK")
    private String link;
    
    @Column(name = "MENU_SORTNUM")
    private Integer sort;
    
    @JsonProperty("parentId")
    @Column(name = "MENU_PARENTID")
    private Long parentId;
    
    @Column(name = "CREATE_USER")
    private String createUser;
    
    @Column(name = "CREATE_TIME")
    private Date createTime;
    
    @Column(name = "UPDATE_TIME")
    private Date updateTime;
    
    @JsonIgnore
    @Transient
    private List<SysMenu> childMenus;
    
    @JsonIgnore
    @OneToMany(mappedBy = "menu", fetch = FetchType.EAGER, cascade = CascadeType.ALL)
    private List<Button> childButton;
    
    @Transient
    private boolean checked;
    
    @Transient
    private String state;
    
    public boolean isChecked()
    {
        return checked;
    }
    
    public void setChecked(boolean checked)
    {
        this.checked = checked;
    }
    
    public List<SysMenu> getChildMenus()
    {
        return childMenus;
    }
    
    public void setChildMenus(List<SysMenu> childMenus)
    {
        this.childMenus = childMenus;
    }
    
    public List<Button> getChildButton()
    {
        return childButton;
    }
    
    public void setChildButton(List<Button> childButton)
    {
        this.childButton = childButton;
    }
    
    public String getState()
    {
        if (0 == this.getParentId())
            return "closed";
        return null;
    }
    
    public int hashCode()
    {
        return 1;
    }
    
    public void setState(String state)
    {
        this.state = state;
    }
    
    @Override
    public String toString()
    {
        return ToStringBuilder.reflectionToString(this);
    }
    
}